package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.QaListBean;
import cn.bocweb.spinning.util.DeviceUtil;
import cn.bocweb.spinning.view.common.GlideCircle;
import cn.bocweb.spinning.view.common.MyAdapter;

/**
 * Created by chenchangxing on 16/6/28.
 */
public class MainForum2Adapter extends MyAdapter<QaListBean.DataBean> {


    public MainForum2Adapter(Context context, List<QaListBean.DataBean> list) {
        super(context, list);
    }

//    @Override
//    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
//        ViewHolder holder1 = (ViewHolder) holder;
//        Glide
//                .with(mContext)
//                .load(mList.get(position).getUthumb())
//                .placeholder(R.mipmap.login_head)
//                .transform(new GlideCircle(mContext))
//                .into(holder1.mIcon);
//        holder1.mNickName.setText(mList.get(position).getNickname());
//        holder1.mContent.setText(mList.get(position).getContent());
//        if (mList.get(position).getPhoto() != null) {
//            for (int i = 0; i < mList.get(position).getPhoto().size(); i++) {
//                Glide
//                        .with(mContext)
//                        .load(mList.get(position).getPhoto().get(i))
//                        .transform(new GlideCircle(mContext))
//                        .into((ImageView) holder1.mLvImg.getChildAt(i));
//            }
//        }
//        holder1.mReply.setText(String.valueOf(mList.get(position).getReply()));
//        holder1.mTime.setText(
//                DeviceUtil.getTimeByTwoTimeStampForPhp(
//                        Long.parseLong(mList.get(position).getTimeline()) * 1000,
//                        System.currentTimeMillis()));
//    }
//
//    @Override
//    public int getItemCount() {
//        return mList.size();
//    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder1;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_main_forum1, parent, false);
            holder1 = new ViewHolder(convertView);
            convertView.setTag(holder1);
        } else {
            holder1 = (ViewHolder) convertView.getTag();
        }

        Glide
                .with(context)
                .load(list.get(position).getUthumb())
                .placeholder(R.mipmap.login_head)
                .transform(new GlideCircle(context))
                .into(holder1.mIcon);
        holder1.mNickName.setText(list.get(position).getNickname());
        holder1.mContent.setText(list.get(position).getContent());
        holder1.mReply.setText(String.valueOf(list.get(position).getReply()));
        holder1.mTime.setVisibility(View.GONE);
        holder1.mTitle.setVisibility(View.GONE);
        holder1.mTvTime.setText(
                DeviceUtil.getTimeByTwoTimeStampForPhp(
                        Long.parseLong(list.get(position).getTimeline()) * 1000,
                        System.currentTimeMillis()));
        if (list.get(position).getStatus().equals("1")) {
//            holder1.mTvAnswer.setText("已解决");
//            holder1.mIvAnswer.setImageResource(R.mipmap.);
            holder1.mIvAnswer.setImageResource(R.mipmap.main_bbs_y);
        } else {
//            holder1.mTvAnswer.setText("未解决");
            holder1.mIvAnswer.setImageResource(R.mipmap.main_bbs_n);
        }
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.icon)
        ImageView mIcon;
        @Bind(R.id.nick_name)
        TextView mNickName;
        @Bind(R.id.time)
        TextView mTime;
        @Bind(R.id.reply)
        TextView mReply;
        @Bind(R.id.iv_answer)
        ImageView mIvAnswer;
        @Bind(R.id.tv_answer)
        TextView mTvAnswer;
        @Bind(R.id.lv_answer)
        LinearLayout mLvAnswer;
        @Bind(R.id.title)
        TextView mTitle;
        @Bind(R.id.content)
        TextView mContent;
        @Bind(R.id.tv_time)
        TextView mTvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
